package com.example.mapper;

import com.example.entity.SysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

public interface SysUsrMapper extends JpaRepository<SysUser,Long> {
    List<SysUser> findByUsrNameAndUsrPassword(String usrName,String usrPassword);



    @Query(nativeQuery = true, value ="select u.*,r.role_name from sys_user u left join sys_role as r on u.usr_role_id = r.role_id where u.usr_name=:uName and u.usr_password=:pwd")
    SysUser selectAll(@Param("uName") String usrName, @Param("pwd")String usrPassword);

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "INSERT INTO `crm`.`sys_user`( `usr_name`, `usr_password`, `usr_role_id`, `usr_flag`) VALUES " +
            "(:#{#user.usrName},:#{#user.usrPassword},:#{#user.sysRole.roleId},:#{#user.usrFlag});\n")
             int addUser(SysUser user);   //添加




}
